<?php

namespace App\Jobs;

use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Mail;

class SendErrorMailJob extends Job implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels;
    protected $error;
    protected $e_name;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($error,$e_name)
    {
        $this->error = $error;
        $this->e_name = $e_name;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if ($this->attempts() > 2) {
            $this->delete();
            return;
        }
        Mail::raw($this->error, function ($m) {
            $time = date('Y-m-d H:i:s');
            $m->from(config('mail.username'), $this->e_name);
            $m->to('dejavuzhou@qq.com', 'CTO站长')->subject($time);
        });
    }
}
